package com.recommend.controller.admin;

import com.recommend.domain.EvaluateDomain;
import com.recommend.domain.MovieDomain;
import com.recommend.service.EvaluateService;
import com.recommend.service.RecommendService;
import com.recommend.service.ScoreService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by lw.
 */
@RestController
@RequestMapping("/admin/score")
public class ScoreController {
    private final static Logger logger = LoggerFactory.getLogger(LoginController.class);

    @Resource
    private ScoreService scoreService;
    @Resource
    private RecommendService recommendService;
    @Resource
    private EvaluateService evaluateService;

    @RequestMapping(value = "/getTopMovies", method = RequestMethod.POST)
    @ResponseBody
    public List<MovieDomain> getTopMovies(){
        logger.info("==============================get top movie controller============");
        return scoreService.getTopMovie();
    }

    @RequestMapping(value = "/getTopMoviesByCustomer", method = RequestMethod.POST)
    @ResponseBody
    public List<MovieDomain> getTopMoviesByCustomer(Integer customerId){
        EvaluateDomain evaluateDomain = evaluateService.getByCustomerId(customerId);
        if(evaluateDomain == null){ //说明该用户没有评分，推荐评分高的电影
            logger.info("==============================get top movie controller. all============");
            return scoreService.getTopMovie();
        }else{
            logger.info("======================get top movie controller, scored============");
            return recommendService.getRecommendByCustomerId(customerId);
        }
    }
}
